<%@ page import="ro.xblue.translator.LanguageBean,
                 ro.xblue.translator.TranslatorUtils,
                 ro.gateway.aida.obj.Currency,
                 ro.gateway.aida.fnd.*,
                 java.text.NumberFormat,
                 ro.gateway.aida.admin.ActivityObjectsOptions,
                 ro.gateway.aida.admin.ActObjsOptsConst,
			  ro.gateway.aida.admin.PropertyListItem,
			  ro.gateway.aida.obj.Organization"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/translator.tld" prefix="trans" %>
<%@ taglib uri="/WEB-INF/taglib.tld" prefix="gtw" %>
<bean:define id="item" name="funding_form" property="item" scope="session" type="ro.gateway.aida.fnd.FundingItem"/>
<bean:define id="form_item" name="funding_form" scope="session" type="ro.gateway.aida.fnd.FundingForm"/>
<html:html>
<%LanguageBean lang_bean = TranslatorUtils.getCurrentLanguage(request, application);%><head>
<%NumberFormat nf = NumberFormat.getInstance(lang_bean.locale);%>
<LINK rel="stylesheet" type="text/css" href="<html:rewrite page='/alf.css'/>">
<SCRIPT LANGUAGE="JavaScript">
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
countfield.value = maxlimit - field.value.length;
}


<%       ActivityObjectsOptions aoo = ActivityObjectsOptions.getInstance(); %>
</script>
</head><trans:initPage module="fundedit" />
<body bgcolor="#FFFFFF" text="#000000">
      <html:form action="/fnd2/editor" styleClass="text_searchbold">
      <bean:define id="form" name="funding_form" />
      <table width="90%" border="0" cellspacing="1" cellpadding="4" align="center" bgcolor="#3399cc" class=text_searchbold>
            <tr bgcolor="#FFFFFF">
                  <td class="textalb" bgcolor="3399cc">
                  <trans:showPageMessage label="fundedit.fundingitemeditor" />
                  </td>
            </tr>

            <tr bgcolor="#FFFFFF"><td>
            <table width="100%" border="0" bgcolor="#3399cc" cellspacing="1" cellpadding="4" class=text_searchbold>
                  <!-- Organization -->
                  <tr bgcolor="#FFFFFF">
                  <td align="right" width="15%" valign="top">
                  <trans:showPageMessage label="fundedit.organization" />
                  </td>
                  <td align="left" width="75%">
                        <logic:present name="organization">
                              <a title="<%=((Organization)request.getAttribute("organization")).getDescription()%>">
                              <%=((Organization)request.getAttribute("organization")).getName()%>
                              </a>
                        </logic:present>
                        <logic:notPresent name="organization">
                        <trans:showPageMessage label="fundedit.noorgfound" />
                        </logic:notPresent>
                  </td>
                  </tr>

                  <!-- Persons -->
<%--                  <tr bgcolor="#FFFFFF">--%>
<%--                  <td align="right" width="15%" valign="top">--%>
<%--                  <trans:showPageMessage label="fundedit.persinv" />:--%>
<%--                  </td>--%>
<%--                  <td align="left" width="75%">--%>
<%--                  <logic:present name="persons" scope="request">--%>
<%--                  <html:select property="personIds" multiple="true" size="5"  >--%>
<%--                        <html:options collection="persons"--%>
<%--                              property="id"--%>
<%--                              labelProperty="fullName" />--%>
<%--                  </html:select>--%>
<%--                  </logic:present>--%>
<%--                  <logic:notPresent name="persons" scope="request">--%>
<%--                        ----%>
<%--                  </logic:notPresent>--%>
<%--                  </td>--%>
<%--                  </tr>--%>

                  <!-- Funding type -->
<%--                  <tr bgcolor="#FFFFFF">--%>
<%--                  <td align="right" width="15%" valign="top">--%>
<%--                  <trans:showPageMessage label="fundedit.fundingtype" />:--%>
<%--                  </td>--%>
<%--                  <td align="left" width="75%">--%>
<%--                  <logic:present name="types" scope="request">--%>
<%--                  <html:select property="fundingType" >--%>
<%--                        <logic:iterate id="type" name="types">--%>
<%--                              <option <%=((FundingType)type).getId() == ((FundingForm)form).getFundingType() ? "selected=\"true\"" : ""%>--%>
<%--                              value="<%=((FundingType)type).getId()%>"><%=((FundingType)type).getName(lang_bean.language)%></option>--%>
<%--                        </logic:iterate>--%>
<%--                  </html:select>--%>
<%--                  </logic:present>--%>
<%--                  <logic:notPresent name="types" scope="request">--%>
<%--                        <trans:showPageMessage label="fundedit.na" />--%>
<%--                  </logic:notPresent>--%>
<%--                  </td>--%>
<%--                  </tr>--%>


                  <!-- Types of assistance -->
      <% if (aoo.isEnabled(ActObjsOptsConst.FUNDING_TYPESASSIST)) { %>
                  <tr bgcolor="#FFFFFF">
                  <td align="right" width="15%" valign="top">
                  <trans:showPageMessage label="fundedit.typesassist" />:
                  </td>
                  <td align="left" width="75%">
                  <logic:present name="form_item" property="typesofassistance">
                  <html:select property="typeofassistanceid" >
                        <logic:iterate id="type" name="form_item" property="typesofassistance" type="ro.gateway.aida.admin.PropertyListItem">
                              <option <%=type.getId() == (item.getType_of_assistance() != null ? item.getType_of_assistance().getId() : -1) ? "selected=\"true\"" : ""%>
                              value="<%=type.getId()%>"><%=type.getString(lang_bean.language)%></option>
                        </logic:iterate>
                  </html:select>
                  </logic:present>
                  <logic:notPresent name="form_item" property="typesofassistance">
                       <trans:showPageMessage label="fundedit.na" />
                  </logic:notPresent>
                  </td>
                  </tr>
       <% } %>

                  <!-- Funding status -->

	   <% if (aoo.isEnabled(ActObjsOptsConst.FUNDING_STATUS)) { %>
                  <tr bgcolor="#FFFFFF">
                  <td align="right" width="15%" valign="top">
                  <trans:showPageMessage label="fundedit.fundingstatus" />:
                  </td>
                  <td align="left" width="75%">
                  <logic:present name="form_item" property="statuses">
                  <html:select property="status" >
                        <logic:iterate id="status" name="form_item" property="statuses" type="ro.gateway.aida.admin.PropertyListItem" >
                              <option <%=(status).getId() == ((FundingForm)form).getStatus() ? "selected=\"true\"" : ""%>
                              value="<%=(status).getId()%>"><%=(status).getString(lang_bean.language)%></option>
                        </logic:iterate>
                  </html:select>
                  </logic:present>
                  <logic:notPresent name="form_item" property="statuses" >
                       <trans:showPageMessage label="fundedit.na" />
                  </logic:notPresent>
                  </td>
                  </tr>
          <% } %>

                  <!-- Terms of assistance -->
                  <tr bgcolor="#FFFFFF">
                  <td align="right" width="15%" valign="top">
                  <trans:showPageMessage label="fundedit.termsassist" />:
                  </td>
                  <td align="left" width="75%">
                  <logic:present name="form_item" property="termsofassistance">
                  <html:select property="termofassistanceid" >
                        <logic:iterate id="type" name="form_item" property="termsofassistance" type="ro.gateway.aida.admin.PropertyListItem">
                              <option <%=type.getId() == (item.getTerms_of_assistance() != null ? item.getTerms_of_assistance().getId() : -1) ? "selected=\"true\"" : ""%>
                              value="<%=type.getId()%>"><%=type.getString(lang_bean.language)%></option>
                        </logic:iterate>
                  </html:select>
                  </logic:present>
                  <logic:notPresent name="form_item" property="termsofassistance">
                       <trans:showPageMessage label="fundedit.na" />
                  </logic:notPresent>
                  </td>
                  </tr>

                  <!-- Amount / currency -->
                  <tr bgcolor="#FFFFFF">
                  <td align="right" width="15%" valign="top">
                  <trans:showPageMessage label="fundedit.amount" />:
                  </td>
                  <td align="left" width="75%">
                  <input type="text" name="amount" value="<%=nf.format(item.getAmount())%>"/>, <trans:showPageMessage label="fundedit.currency" />

                  <logic:present name="form_item" property="currencies">
                  <html:select property="currency" >
                        <logic:iterate id="currency" name="form_item" property="currencies" type="Currency" >
                              <% if (currency.getIso3() != null) { %>
                              <option <%=(currency).getIso3().equals(((FundingForm)form).getCurrency()) ? "selected=\"true\"" : ""%>
                              value="<%=(currency).getIso3()%>"><%=(currency).getIso3()%></option>
                              <% } %>
                        </logic:iterate>
                  </html:select>
                  </logic:present>
                  <logic:notPresent name="form_item" property="currencies">
                        <trans:showPageMessage label="fundedit.na" />
                  </logic:notPresent>
                  </td>
                  </tr>
            </table>
            </td></tr>

		  <% if (aoo.isEnabled(ActObjsOptsConst.FUNDING_SIGDATE)) { %>
            <tr bgcolor="#FFFFFF">
			<td align="center">
			<trans:showPageMessage label="fundedit.signaturedate" />:
			<gtw:dateSelector zname="z_sign" lname="l_sign" aname="a_sign" current_value="<%=item.getSignature_date()%>" />
			</td>
            </tr>
		<% } %>
            <tr bgcolor="#FFFFFF">
			<td align="center">
			<trans:showPageMessage label="fundedit.commitments" />:
			<table width="100%" border="0" bgcolor="#3399cc" cellspacing="1" cellpadding="4" class=text_searchbold>
				<tr bgcolor="3399cc" class="textalb">
					<td><trans:showPageMessage label="fundedit.delete" /></td>
					<td><trans:showPageMessage label="fundedit.year" /></td>
					<td><trans:showPageMessage label="fundedit.total" /></td>
					<td><trans:showPageMessage label="fundedit.datecommited" /></td>
				</tr>
				<logic:iterate id="titem" name="item" property="commitments" indexId="i" type="ro.gateway.aida.fnd.FundingTableItem">
				<tr bgcolor="#FFFFFF" class="text_search">
					<td><input type="checkbox" name="comsidxs" value="<%=i%>"></td>
					<td>
					<select name="commyear<%=i%>">
					<% for (int k = 1970; k <= 2025; k++) { %>
					<option <%=titem.getYear() == k ? "selected=\"true\"" : ""%> value="<%=k%>"><%=k%></option>
					<% } %>
					</select>
					</td>
					<td>
						<input type="text" name="camount<%=i%>" value="<%=nf.format(titem.getAmount())%>"/>
						<select name='<%="ccurrency" + i%>' >
						<logic:iterate id="currency" name="form_item" property="currencies" type="Currency" >
							<% if (currency.getIso3() != null) { %>
							<option <%=(currency).getIso3().equals(titem.getCurrency()) ? "selected=\"true\"" : ""%>
							value="<%=(currency).getIso3()%>"><%=(currency).getIso3()%></option>
							<% } %>
						</logic:iterate>
					</td>
					<td>
						<gtw:dateSelector zname='<%="cz" + i%>' lname='<%="cl" + i%>' aname='<%="ca" + i%>'
 							current_value="<%=titem.getDate()%>" />
					</td>
				</tr>
				</logic:iterate>
			</table>
			<input class="butonsave" type="button" name="xx1" value="<trans:showPageMessage label="fundedit.deleterow" hide_link="true" />"
				onclick="this.form.event.value='delcommitments';this.form.submit();"/>
			<input class="butonsave" type="button" name="xx1" value="<trans:showPageMessage label="fundedit.addrow" hide_link="true" />"
				onclick="this.form.event.value='addcommitments';this.form.submit();"/>
			<br/>
			<br/>
			<br/>
			<trans:showPageMessage label="fundedit.disbursement" />:
			<table width="100%" border="0" bgcolor="#3399cc" cellspacing="1" cellpadding="4" class=text_searchbold>
				<tr bgcolor="3399cc" class="textalb">
					<td><trans:showPageMessage label="fundedit.delete" /></td>
					<td><trans:showPageMessage label="fundedit.year" /></td>
					<td><trans:showPageMessage label="fundedit.total" /></td>
					<td><trans:showPageMessage label="fundedit.datedisbursed" /></td>
				</tr>
				<logic:iterate id="titem" name="item" property="disbursements" indexId="i" type="ro.gateway.aida.fnd.FundingTableItem">
				<tr bgcolor="#FFFFFF" class="text_search">
					<td><input type="checkbox" name="disbsidxs" value="<%=i%>"></td>
					<td>
					<select name="disbyear<%=i%>">
					<% for (int k = 1970; k <= 2025; k++) { %>
					<option <%=titem.getYear() == k ? "selected=\"true\"" : ""%> value="<%=k%>"><%=k%></option>
					<% } %>
					</select>
					</td>
					<td>
						<input type="text" name="damount<%=i%>" value="<%=nf.format(titem.getAmount())%>"/>
						<select name='<%="dcurrency" + i%>' >
						<logic:iterate id="currency" name="form_item" property="currencies" type="Currency" >
							<% if (currency.getIso3() != null) { %>
							<option <%=(currency).getIso3().equals(titem.getCurrency()) ? "selected=\"true\"" : ""%>
							value="<%=(currency).getIso3()%>"><%=(currency).getIso3()%></option>
							<% } %>
						</logic:iterate>
					</td>
					<td>
						<gtw:dateSelector zname='<%="dz" + i%>' lname='<%="dl" + i%>' aname='<%="da" + i%>'
 							current_value="<%=titem.getDate()%>" />
					</td>
				</tr>
				</logic:iterate>
			</table>
			<input class="butonsave" type="button" name="xx1" value="<trans:showPageMessage label="fundedit.deleterow" hide_link="true" />"
				onclick="this.form.event.value='deldisbursements';this.form.submit();"/>
			<input class="butonsave" type="button" name="xx1" value="<trans:showPageMessage label="fundedit.addrow" hide_link="true" />"
				onclick="this.form.event.value='adddisbursements';this.form.submit();"/>
			</td>
            </tr>

            <tr bgcolor="#FFFFFF">
			<td align="left">
			<table width="100%" border="0" bgcolor="#3399cc" cellspacing="0" cellpadding="4" class=text_searchbold>
				<tr bgcolor="#FFFFFF">
				<td align="right" width="15%" valign="top">
				<trans:showPageMessage label="fundedit.comment" />:
				</td>
				<td align="left" width="75%">
					<html:textarea property="comment" cols="35" rows="3" onkeydown="textCounter(this.form.comment,this.form.ccomment,512);" onkeyup="textCounter(this.form.comment,this.form.ccomment,512);"/><br/>
					<input readonly type="text" name="ccomment" size="3" maxlength="4" value=""> <trans:showPageMessage label="fundedit.charactersleft" />
				</td>
				</tr>
			</table>
			</td>
            </tr>

            <script language="javascript">
               function save(forma) {
                    forma.event.value='save';
                    forma.submit();
               }
            </script>
            <input type="hidden" name="event" value=""/>
            <tr bgcolor="#FFFFFF">
                  <td align="center">
                  <input type="button" name="x1" class="butonsave"
                    onclick="javascript:save(this.form);" value="<trans:showPageMessage label="fundedit.save" hide_link="true" />" />
                  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                  <input type="button" name="x2" class="butonsave"
                    onclick="javascript:window.close();" value="<trans:showPageMessage label="fundedit.cancel" hide_link="true" />" />
                  </td>
            </tr>
      </table><trans:showPageMessage label="translator.showhiddentags"/>
      </html:form>
<div id="loading" style="position: relative;visibility: hidden;height:40px;width:50%;left: 25%;top:5%;text-align: center;vertical-align: middle;border: 1px dotted;background-color: #f2f2f2;" class="text_searchbold"> 
  Loading...<br>
  Please wait<br>
</div>
</body>
</html:html>
